#define DEBUG
#include <cstdio>
#define MAXN 50000

using namespace std;

int main() {
#ifdef DEBUG
  freopen("4377.in", "r", stdin);
  freopen("4377.out", "w", stdout);
#endif

  static int power[4];
  power[0]=1;
  for (int i=1; i<4; i++) {
    power[i] = power[i-1]*37;
  }

  static int word[MAXN+1];
  int n, d;
  scanf("%d %d", &n, &d);
  for (int i=1; i<=n; i++) {
    char c;
    for (int j=0; j<4; j++) {
      scanf(" %c ", &c);
      if (c>='0' && c<='9') {
	word[i] = word[i]*37+c-'0'+1;
      } else {
	word[i] = word[i]*37+c-'a'+11;
      }
    }
  }

  static int f[5], book[1874161];
  for (int i=0; i<(1<<4); i++) {
    for (int j=1; j<=n; j++) {
      int t=0, val=0;
      for (int k=0; k<4; k++) {
	if ((1<<k)&i) {
	  t+=word[j]/power[k]%37*power[k];
	  val++;
	}
      }
      f[val]+=book[t];
      book[t]++;
    }
  }

  int g[5];
  g[0]=f[4];
  g[1]=f[3]-4*g[0];
  g[2]=f[2]-6*g[0]-3*g[1];
  g[3]=f[1]-4*g[0]-3*g[1]-2*g[2];
  g[4]=f[0]-g[0]-g[1]-g[2]-g[3];
  printf("%d", g[d]);

  fclose(stdin);
  fclose(stdout);
  return 0;
}
